"""
Created on 27-Oct-2009

@author: dexen
"""

import os
import sys
import time
import rpyc

import dexen
from dexen.system.base import service

from tasks import development, evaluation, feedback, initialization

def main():
    spec = dexen.DexenSpec("Spec1")
    spec.register_task(development.DevelopmentTask, 100)
    spec.register_task(evaluation.EvaluationTask, 100)
    spec.register_task(feedback.FeedbackTask, 400)
    spec.register_init(initialization.InitializationTask)
    schema_dir = os.getcwd()
    spec.set_schema("pbv1", schema_dir)
    
    for task in spec.tasks:
        print task

   
    conn = rpyc.connect(sys.argv[1], service.REGISTRY_PORT,
                        config=service.default_config)
    
    addr = conn.root.get_node_mgr_addr()
    conn.close()
    
    conn = rpyc.connect(addr[0], addr[1],
                        config=service.default_config)    
    
    conn.root.run_schema(spec)
    #conn.root.add_slaves(["SLAVE1"])
    
    #time.sleep(20)
    #print "adding 2nd slave..."
    #conn.root.add_slaves(["SLAVE2"])
    
    #scheduler.test_run(sp

if __name__ == "__main__":
    main()
